package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.hotel.domain.vo.DicPositionLabelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.hotel.domain.DicPositionLabel;
import com.ktgj.hotel.service.IDicPositionLabelService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-12-09
 */
@ControllerAdvice
@RestController
@RequestMapping("/label")
public class DicPositionLabelController extends BaseController
{
    @Autowired
    private IDicPositionLabelService dicPositionLabelService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:label:list")
    @GetMapping("/list")
    public TableDataInfo list(DicPositionLabel dicPositionLabel)
    {
        startPage();
        List<DicPositionLabel> list = dicPositionLabelService.selectDicPositionLabelList(dicPositionLabel);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:label:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DicPositionLabel dicPositionLabel) throws IOException
    {
        List<DicPositionLabel> list = dicPositionLabelService.selectDicPositionLabelList(dicPositionLabel);
        ExcelUtil<DicPositionLabel> util = new ExcelUtil<DicPositionLabel>(DicPositionLabel.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "hotel:label:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dicPositionLabelService.selectDicPositionLabelById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:label:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DicPositionLabel dicPositionLabel)
    {
        return toAjax(dicPositionLabelService.insertDicPositionLabel(dicPositionLabel));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:label:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DicPositionLabel dicPositionLabel)
    {
        return toAjax(dicPositionLabelService.updateDicPositionLabel(dicPositionLabel));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:label:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dicPositionLabelService.deleteDicPositionLabelByIds(ids));
    }

    /**
     * 查询酒店区域位置筛选条件
     * */
    @PostMapping("/filterCondition")
    public AjaxResult filterCondition(@RequestBody Map<String, Object> map){
        Long cityCountyId = null;
        String lng = null;
        String lat = null;
        String cityCountyName = null;
        try {
            if (map.get("cityCountyId") != null){
                cityCountyId = Long.valueOf(map.get("cityCountyId").toString());
            }
            if (map.get("lng") != null && map.get("lat") != null){
                lng = map.get("lng").toString();
                lat = map.get("lat").toString();
            }
            if (map.get("cityCountyName") != null){
                cityCountyName = map.get("cityCountyName").toString();
            }
        } catch (Exception e){
            return AjaxResult.error("参数传入异常");
        }

        if ((cityCountyId != null && cityCountyId != 0) || (lng != null && !lng.equals("") && lat != null && !lat.equals(""))){
            List<DicPositionLabelVo> dicPositionLabelVoList;
            try {
                if (cityCountyName != null && !cityCountyName.equals("")){
                    dicPositionLabelVoList = dicPositionLabelService.condition(cityCountyName, lng, lat);
                }
                else {
                    dicPositionLabelVoList = dicPositionLabelService.filterCondition(cityCountyId, lng, lat);
                }
            } catch (Exception e){
                return AjaxResult.error(e.getMessage());
            }

            if (dicPositionLabelVoList != null && dicPositionLabelVoList.size() > 0){
                return AjaxResult.success(dicPositionLabelVoList);
            }
            else {
                return AjaxResult.error("未查询到酒店筛选条件");
            }
        }
        else {
            return AjaxResult.error("未传入指定参数");
        }
    }

    /**
     * 查询酒店筛选筛选条件
     * */
    @PostMapping("/filter")
    public AjaxResult filter(){
        List<DicPositionLabelVo> dicPositionLabelVoList;
        try {
            dicPositionLabelVoList = dicPositionLabelService.filter();
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        if (dicPositionLabelVoList != null && dicPositionLabelVoList.size() > 0){
            return AjaxResult.success(dicPositionLabelVoList);
        }
        else {
            return AjaxResult.error("未查询到酒店筛选条件");
        }
    }
}
